﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WDA.Public
{
   /// <summary>
   /// WDAB facade interface. It represents whole WDAB instance.
   /// </summary>
   public interface IServices : IDisposable
   {
      /// <summary>
      /// Returns proxy for service of given contract type. 
      /// This method should be avoided because introduces potential problems with not closing the proxy properly. 
      /// Please use <see cref="Communicate{T}"/> or <see cref="Communicate{T,TResult}"/> instead.
      /// </summary>
      /// <remarks>
      /// Usually caller of the method is responsible for closing returned proxy after using it. For
      /// detailed information please refer to documentation of particular WDAB module.
      /// </remarks>
      /// <param name="serviceType">CLR type of service contract.</param>
      /// <returns>A proxy object.</returns>
      object Get(Type serviceType);      
      /// <summary>
      /// Returns proxy for service of given contract type.
      /// This method should be avoided because introduces potential problems with not closing the proxy properly. 
      /// Please use <see cref="Communicate{T}"/> or <see cref="Communicate{T,TResult}"/> instead.
      /// </summary>
      /// <remarks>
      /// Usually caller of the method is responsible for closing returned proxy after using it. For
      /// detailed information please refer to documentation of particular WDAB module.
      /// </remarks>
      /// <typeparam name="T">CLR type of service contract.</typeparam>
      /// <returns>A proxy object.</returns>
      T Get<T>();
      /// <summary>
      /// Executes provided action against proxy to WDAB service. Method internally manages proxy lifecycle (closing).
      /// </summary>
      /// <typeparam name="T">CLR type of service contract.</typeparam>      
      /// <param name="proxyAction">Action to execute.</param>
      /// <example>
      /// srv.Communicate&gt;IPrinterService&lt;(proxy => proxy.Print("Something to be printed");
      /// </example>
      void Communicate<T>(Action<T> proxyAction);
      /// <summary>
      /// Executes proviedef function againts proxt to WDAB service. Method internally manages proxy lifecycle (closing).
      /// </summary>
      /// <typeparam name="TResult">Typ zwracany przez czynność.</typeparam>
      /// <typeparam name="T">CLR type of service contract.</typeparam>
      /// <param name="proxyAction">Akcja do wykonania.</param>
      /// <returns></returns>
      /// <example>
      /// srv.Communicate&gt;IConverterService,int&lt;(proxy => proxy.ConvertToInt("15");
      /// </example>
      TResult Communicate<T, TResult>(Func<T, TResult> proxyAction);
   }
}
